/*
 * Random numbers testing suite (that word!).
 */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <limits.h>

#define INVAL_ARGS	(1)

int first_func_limit = RAND_MAX; /* ?? */
int second_func_limit = RAND_MAX; /* ? */


int
first_rand(int lim)
{
	return rand() % lim;
}

int
second_rand_naive(int lim)
{
	return 42;
}

int
second_rand(int lim)
{
	return 42;
}

int
test1_std_rand_randomness(const long long iter_num, int limit)
{
	register int x = 0;
	register long long i = 0;
	double *freq = NULL;

	if (!limit)
		return INVAL_ARGS;

	/*
	 * Count frequencies of numbers in [0 ; limit - 1] segment
	 */
	freq = calloc(limit, sizeof *freq);
	for (; i < iter_num; i++) {
		x = rand() % limit;
		freq[x]++;
	}
	for (i = 0; i < limit; i++) {
		freq[i] /= iter_num;
		printf("%12lld: %.8lf\n", i, freq[i]);
	}

	free(freq);
	return 0;
}

int
main(int argc, char **argv)
{
	long count = 1;
	long long iter_n = 0;
	int lim = 0;

	if (argc != 3) {
		(void) fprintf(stderr, "%s: usage: "
				"%s <iteration count> <limit>\n",
				argv[0], argv[0]);
		exit(EXIT_FAILURE);
	}

	iter_n = atoi(argv[1]);
	lim    = atoi(argv[2]);

	test1_std_rand_randomness(iter_n, lim);

	return EXIT_SUCCESS;
}
